import Service from '@/api/httpAxios'

export interface ProcessParamType {
  project_id: string
  offset?: number
  limit?: number
  fleet_id?: string
  url?: string
  autoScaling?: object
  policy_id?: string
}

class autoScaling {
  getFleetList = (obj: ProcessParamType) => {
    let pid
    obj.project_id ? (pid = obj.project_id) : (pid = localStorage.getItem('project_id'))
    const url = `/v1/${pid}/monitor-fleets`
    return Service.get<any>(url)
  }
  getAutoScalingList = (obj: ProcessParamType) => {
    let pid
    obj.project_id ? (pid = obj.project_id) : (pid = localStorage.getItem('project_id'))
    const url = `/v1/${pid}/fleets/scaling-policies`
    return Service.get<any>(url, {
      params: {
        offset: obj.offset ? obj.offset - 1 : obj.offset,
        limit: obj.limit
      }
    })
  }
  createAutoScaling = (obj: ProcessParamType) => {
    let pid
    obj.project_id ? (pid = obj.project_id) : (pid = localStorage.getItem('project_id'))
    const url = `/v1/${pid}/fleets/scaling-policies`
    return Service.post<any>(url, obj.autoScaling)
  }
  changeAutoScaling = (obj: any) => {
    let pid
    obj.project_id ? (pid = obj.project_id) : (pid = localStorage.getItem('project_id'))
    const url = `/v1/${pid}/fleets/scaling-policies/${obj.policy_id}`
    return Service.put<any>(url, obj.autoScaling)
  }
  deleteAutoScaling = (obj: ProcessParamType) => {
    let pid
    obj.project_id ? (pid = obj.project_id) : (pid = localStorage.getItem('project_id'))
    const url = `/v1/${pid}/fleets/scaling-policies/${obj.policy_id}`
    return Service.delete<any>(url)
  }
  getAutoScalingFleet = (obj: ProcessParamType) => {
    let pid
    obj.project_id ? (pid = obj.project_id) : (pid = localStorage.getItem('project_id'))
    const url = `/v1/${pid}/fleets/scaling-policies/${obj.policy_id}/bind`
    return Service.get<any>(url, {
      params: {
        offset: obj.offset ? obj.offset - 1 : obj.offset,
        limit: obj.limit
      }
    })
  }
  toBindAutoScaling = (obj: ProcessParamType) => {
    let pid
    obj.project_id ? (pid = obj.project_id) : (pid = localStorage.getItem('project_id'))
    const url = `/v1/${pid}/fleets/${obj.fleet_id}/scaling-policies/${obj.policy_id}/bind`
    return Service.put<any>(url, {
    })
  }
  deleteAutoFleet = (obj: any) => {
    let pid
    obj.project_id ? (pid = obj.project_id) : (pid = localStorage.getItem('project_id'))
    const url = `/v1/${pid}/fleets/${obj.fleet_id}/scaling-policies/${obj.policy_id}/bind`
    return Service.delete<any>(url)
  }
  getFleetScaling = (obj: ProcessParamType) => {
    let pid
    obj.project_id ? (pid = obj.project_id) : (pid = localStorage.getItem('project_id'))
    const url = `/v1/${pid}/fleets/${obj.fleet_id}/bind`
    return Service.get<any>(url)
  }
  getDetails = (obj: ProcessParamType) => {
    let pid
    obj.project_id ? (pid = obj.project_id) : (pid = localStorage.getItem('project_id'))
    const url = `/v1/${pid}/fleets/scaling-policies/${obj.policy_id}`
    return Service.get<any>(url)
  }
}

export default new autoScaling()
